﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Public;

namespace Dal
{
    public class Admin
    {
        #region 登录判断
        /// <summary>
        /// 登录判断
        /// </summary>
        /// <param name="strCon"></param>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public DataTable Login(string strCon, string name, string password)
        {
            //新建一张表，保存数据
            DataTable dtAdmin = new DataTable();

            //设置存储过程参数
            SqlParameter[] pars = new SqlParameter[2];
            pars[0] = new SqlParameter("@AdminName", SqlDbType.NVarChar);
            pars[0].Value = name;
            pars[1] = new SqlParameter("@PassWord", SqlDbType.NVarChar);
            pars[1].Value = DataProtector.MD5Stirng(password);

            try
            {
                //执行存储过程
                dtAdmin = SqlHelper.ExecuteDataTable(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_Admin_SELECT_SINGLE_Password", pars);
            }
            catch (Exception ex)
            {
                // 写日志
                //LogManager.WriteError("后台用户登陆，" + ex.Message + "\n" + ex.StackTrace);
            }

            return dtAdmin;
        }
        #endregion

        #region 修改密码
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="strCon"></param>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public int UpdatePassword(string strCon, string name, string password)
        {
            int rtn = 0;
            //设置存储过程参数
            SqlParameter[] pars = new SqlParameter[2];
            pars[0] = new SqlParameter("@AdminName", SqlDbType.NVarChar);
            pars[0].Value = name;
            pars[1] = new SqlParameter("@PassWord", SqlDbType.NVarChar);
            pars[1].Value = DataProtector.MD5Stirng(password);

            try
            {
                //执行存储过程
                rtn = SqlHelper.ExecuteNonQuery(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_Admin_UpdatePassword", pars);
            }
            catch (Exception ex)
            {
                // 写日志
                //LogManager.WriteError("后台用户登陆，" + ex.Message + "\n" + ex.StackTrace);
            }

            return rtn;
        }
        #endregion

    }
}
